package com.xb.loan.util.log;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.lang.reflect.Proxy;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 日志工厂， 提供logger实例
 */
public class DefaultLoggerFacotry {

	private static Map<String, Logger> loggerMap = new ConcurrentHashMap<String, Logger>();

    /**
    * 
    *根据对象简单类名，返回 Logger对象
    * @return Logger
    */
	public static Logger getLogger(String loggerName) {

		Logger logger = loggerMap.get(loggerName);

		if (logger == null) {
			Logger targetLogger = LoggerFactory.getLogger(loggerName);
			logger = (Logger) Proxy.newProxyInstance(
					Logger.class.getClassLoader(), new Class[] { Logger.class },
					new DefaultLogger(targetLogger));
			loggerMap.put(loggerName, logger);
		}
		return logger;
	};

    /**
     * 
     *根据字节码对象返回 Logger对象
     * @param classz
     * @return Logger
     */
	public static Logger getLogger(Class classz) {
		return getLogger(classz.getName());
	};

}
